#!/usr/local/bin/php -q
<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/08/16 11:45:01 $)
// $RCSfile: index.php,v $ : $Revision: 1.9 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

define("SWIFT_AREA", 60);

chdir(dirname(__FILE__)."/../");
require_once ("./includes/functions_cli.php");
$cli = new CLI;


if (in_array($argv[1], array('--help', '-help', '-h', '-?')))
{
	$cli->writeln($cli->green('===================='));
	$cli->writeln($cli->yellow("SWIFT CLI Debug"));
	$cli->writeln($cli->green('===================='));
	$cli->writeln();

	$result = $cli->prompt("", array("1" => "Exit"));

} else if (in_array($argv[1], array('--rebuildindex', '-rebuildindex'))) {
	require_once ("./swift.php");

	$cli = new CLI;

	if (!$events->triggerEvent(EVENT_CLI)) {
		// Try to do a callback on tickets module for email piping, if unsuccesfull then display default message
		if (!$events->triggerCallback("tickets", "clirebuildindex"))
		{
			echo sprintf($_SWIFT["language"]["clidefault"], SWIFTPRODUCT, $settings->getKey("core", "version"), date("Y"));
		}
	}

} else {
	require_once ("./swift.php");

	if (in_array($argv[1], array('--debug', '-debug', '-d')) || in_array($argv[3], array('--debug', '-debug', '-d')))
	{
		$_SWIFT["clidebug"] = true;
		$_SWIFT["dbgfilename"] = "clidbg_".buildHash();
	}

	if (in_array($argv[1], array('--load', '-load', '-l')) && !empty($argv[2]))
	{
		$_SWIFT["clifileload"] = $argv[2];
	}

	if (!$events->triggerEvent(EVENT_CLI)) {
		// Try to do a callback on tickets module for email piping, if unsuccesfull then display default message
		if (!$events->triggerCallback("parser", "cliparser"))
		{
			echo sprintf($_SWIFT["language"]["clidefault"], SWIFTPRODUCT, $settings->getKey("core", "version"), date("Y"));		
		}
	}
}
?>